{-# OPTIONS -Wall #-}

--------------------------------------------------------------------------------
-- |
-- Module      :  Lirio.Base.Duration
-- Copyright   :  (c) Stephen Tetley 2012
-- License     :  BSD3
--
-- Maintainer  :  Stephen Tetley <stephen.tetley@gmail.com>
-- Stability   :  highly unstable
-- Portability :  GHC
--
-- Duration representation - algebraic type rather than a Doc as
-- we need equality for relative durations.
--
--------------------------------------------------------------------------------



module Lirio.Base.Duration 
  (
  -- * Duration types
    Numeral(..)
  , Duration
  
  , dot
  , components


  -- * Named durations
  , dLonga
  , dBreve
  , dWhole
  , dHalf
  , dQuarter
  , dEighth
  , dSixteenth
  , dThirtySecondth
  
  ) where


data Numeral = N128  | N64   | N32   | N16
             | N8    | N4    | N2    | N1
             | Breve | Longa
  deriving (Enum,Eq,Ord,Show)



data Duration = Duration { _numeral :: Numeral, _dot_count :: Int }
  deriving (Eq,Show)


       
-- | Dot a duration. 
-- 
dot :: Duration -> Duration
dot (Duration n dc) = Duration n (dc+1)


components :: Duration -> (Numeral,Int)
components (Duration n dc) = (n,dc)

--------------------------------------------------------------------------------
-- Named durations


 
makeDuration :: Numeral -> Duration
makeDuration nm = Duration nm 0


dLonga          :: Duration
dLonga          = makeDuration Longa

dBreve          :: Duration
dBreve          = makeDuration Breve

dWhole          :: Duration
dWhole          = makeDuration N1

dHalf           :: Duration
dHalf           = makeDuration N2

dQuarter        :: Duration
dQuarter        = makeDuration N4

dEighth         :: Duration
dEighth         = makeDuration N8

dSixteenth      :: Duration
dSixteenth      = makeDuration N16

dThirtySecondth :: Duration
dThirtySecondth = makeDuration N32



